package com.bestcem.xm.member.mq.receiver;//package com.bestcem.xm.member.mq.receiver;
//
//import com.bestcem.xm.member.mq.MemberTopics;
//import com.bestcem.xm.member.mq.message.WechatMemberSyncMessage;
//import com.bestcem.xm.member.service.WechatService;
//import com.bestcem.xm.util.MsgPackFormatUtil;
//import com.rabbitmq.client.Channel;
//import lombok.extern.slf4j.Slf4j;
//import org.slf4j.Logger;
//import org.slf4j.LoggerFactory;
//import org.springframework.amqp.core.Message;
//import org.springframework.amqp.rabbit.annotation.RabbitListener;
//import org.springframework.stereotype.Component;
//
//import javax.annotation.Resource;
//import java.io.IOException;
//import java.util.Base64;
//
///**
// * 微信公众号同步打开与关闭
// *
// * @author yf.wang <yf.wang@idiaoyan.com>
// * @version V1.0
// * @date 2022/4/1
// */
//
//@Slf4j
//@Component
//public class MemberWechatMemberSyncDelayReceiver {
//    private static final Logger EMAIL_LOG = LoggerFactory.getLogger("EmailErrorLog");
//
//    @Resource
//    private WechatService wechatService;
//
//    @RabbitListener(queues = "#{appMemberWechatMemberSyncDelayQueue.name}", ackMode = "MANUAL",
//            concurrency = "${app.member.wechat.sync-member-delay-concurrency:2}",
//            containerFactory = "appMemberWechatMemberSyncDelayFactory")
//    public void receive(Message message, Channel channel) throws IOException {
//        if (log.isInfoEnabled()) {
//            log.info("【联系人】【延时队列】微信公众号同步打开与关闭信息");
//        }
//        long deliveryTag = message.getMessageProperties().getDeliveryTag();
//        try {
//            MsgPackFormatUtil.MqMessage mqMessage = MsgPackFormatUtil.mqDecode(message.getBody());
//            if (mqMessage == null) {
//                EMAIL_LOG.error("【联系人】【延时队列】微信公众号同步打开与关闭消息解析失败: {}", Base64.getEncoder().encodeToString(message.getBody()));
//                channel.basicNack(deliveryTag, false, false);
//                return;
//            }
//
//            if (MemberTopics.MEMBER_WECHAT_MEMBER_SYNC_DELAY_TOPIC.equals(mqMessage.getTopic())) {
//                WechatMemberSyncMessage wechatMemberSyncMessage = MsgPackFormatUtil.mapToObj(mqMessage.getData(),
//                        WechatMemberSyncMessage.class);
//                wechatService.sendWxSyncMessage(wechatMemberSyncMessage);
//            }
//            channel.basicAck(deliveryTag, false);
//        } catch (Exception e) {
//            EMAIL_LOG.error("【联系人】【延时队列】处理微信公众号同步打开与关闭消息异常:{}", Base64.getEncoder().encodeToString(message.getBody()), e);
//            try {
//                channel.basicNack(deliveryTag, false, false);
//            } catch (Exception e2) {
//                EMAIL_LOG.error("【联系人】【延时队列】处理微信公众号同步打开与关闭消息, nack mq消息异常: {}",
//                        Base64.getEncoder().encodeToString(message.getBody()), e2);
//            }
//        }
//    }
//}
